import 'config/public-path';
import Vue from 'vue';
import App from 'modules/portlet/app.vue';
import { registerGlobalComponents } from './config/iview.js';
import 'view-design/dist/styles/iview.css';

Vue.config.productionTip = false;

registerGlobalComponents(Vue);

let instance = null;

//嵌入示例
function render(props = {}) {
    const { container } = props;
    if(props.fetchOAuth2Code) {
        //待开发
        props.fetchOAuth2Code((code) => {
            console.log(code);
        });
    } 
    if(props.callback) {
        props.callback('信息1', '信息2');
    }
    instance = new Vue({
        render: (h) => h(App),
    }).$mount(container ? container.querySelector('#app') : '#app');
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
    render();
}

export async function bootstrap() {
    
}

export async function mount(props) {
    render(props);
}

export async function update(props) {
    console.log('update props', props);
}

export async function unmount() {
	if(instance) {
	    instance.$destroy();
	    instance.$el.innerHTML = '';
	    instance = null;
    }
    //router = null;
}